package com.c2c.service.impl;

import com.c2c.mapper.CommentMapper;
import com.c2c.po.Comment;
import com.c2c.po.enums.impl.CommentsState;
import com.c2c.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    CommentMapper commentMapper;

    @Override
    public List<Comment> findAllComment() {
        return commentMapper.findAllComment();
    }

    @Override
    public List<Comment> findByUserAccount(int userAccount) {
        return commentMapper.findByUserAccount(userAccount);
    }

    @Override
    public List<Comment> findByGoodsId(int goodsId) {
        return commentMapper.findByGoodsId(goodsId);
    }

    @Override
    public void updateContentByCommentId(Comment comment) {
        comment.setCommentTime(new Date());
        commentMapper.updateContentByCommentId(comment);
    }

    @Override
    public void updateStateByCommentId(Comment comment, int commentState) {
        for (CommentsState commentsState : CommentsState.values()){
            if (commentsState.getCode() == commentState){
                comment.setCommentState(commentsState);
                commentMapper.updateStateByCommentId(comment);
            }
        }
    }

    @Override
    public void deleteByCommentId(int commentId) {
        commentMapper.deleteByCommentId(commentId);
    }

    @Override
    public void insertCommentId(Comment comment) {
        commentMapper.insertCommentId(comment);
    }
}
